<template>
	<u-cell-group :border="false">
		<u-cell-item title="账户" icon="phone" :value="userCode" :arrow="false"></u-cell-item>
		<u-cell-item title="姓名" icon="account" :value="userName" :arrow="false"></u-cell-item>
		<u-cell-item center :value="versionName" :arrow=false title="版本" icon="level">
		</u-cell-item>


		<u-cell-item center @click="about = true" :arrow=true title="关于我们" icon="star-fill" class="separate">
		</u-cell-item>
		<u-cell-item center @click="checkUpdate" :arrow=true title="检查更新" icon="download">
		</u-cell-item>
		<u-cell-item center @click="showPwd = true" :arrow=true title="修改密码" icon="lock-open">
		</u-cell-item>
		<u-cell-item center @click="show = true" :arrow=true title="退出登录" icon="close">
		</u-cell-item>
	</u-cell-group>
	<u-modal v-model="show" :content="content" :show-cancel-button="true" @cancel="cancel" @confirm="confirm">
	</u-modal>
	<u-modal v-model="about" :content="aboutUs" @confirm="about = false" title="优泰科技"></u-modal>
	<u-modal v-model="update" :content="updateContent" @confirm="confirmUpdate" title="优泰科技-更新提示"></u-modal>
	<u-modal v-model="showPwd" ref="uModal1" :show-cancel-button="true" @cancel="cancelPWd" @confirm="confirmPwd"
		:async-close="true" title="修改密码">
		<u-form :model="formPwd" ref="form1" style="padding: 20rpx;">
			<u-form-item label="原始密码" label-width="150" prop="originPwd"><u-input v-model="formPwd.originPwd"
					maxlength="12" type="password" :border="true" :password-icon="true" /></u-form-item>
			<u-form-item label="新的密码" label-width="150" prop="newPwd"><u-input v-model="formPwd.newPwd" maxlength="12"
					type="password" :border="true" :password-icon="true" /></u-form-item>
			<u-form-item label="确认密码" label-width="150" prop="newPwd2"><u-input v-model="formPwd.newPwd2" maxlength="12"
					type="password" :border="true" :password-icon="true" /></u-form-item>

		</u-form>
	</u-modal>
</template>

<script>
	export default {
		data() {
			return {
				userCode: 'mj丶',
				userName: 'mj丶',
				versionName: '1.0.24.0723',
				userPwd: '',
				show: false,
				about: false,
				update: false,
				showPwd: false,
				formPwd: {
					originPwd: '',
					newPwd: '',
					newPwd2: '',
				},
				aboutUs: '版权所有 WMJ保留所有权利         警告：本计算机程序受版权法和国际条约保护。如未经授权而擅自复制或传播本程序（或其中任何部分），将受到严厉的民事和刑事制裁，并将在法律许可的最大限度内受到起诉。',
				content: '退出将不会保存数据，确认退出？',
				updateContent: '版本更新',
				rules: {
					originPwd: [{
						required: true,
						message: '请输入原始密码',
						trigger: ['change', 'blur']
					}],
					newPwd: [{
						required: true,
						message: '请输入新的密码',
						trigger: ['change', 'blur']
					}],
					newPwd2: [{
						required: true,
						message: '请输入确认密码',
						trigger: ['change', 'blur']
					}],
				}
			}
		},
		onMounted() {

		},
		onReady() {
			this.$checkLogin();
			this.$request('User/GetUserAsync','GET',{
				"userCode":this.$globalState.S1600Info.UserCode
			}).then(res=>{
				if(res.code=200){
					this.userCode = res.data.userCode;
					this.userName = res.data.userName;
					this.$globalState.S1600Info.RoleID = res.data.userRole
					console.log(this.$globalState.S1600Info.RoleID)
				}
			})
		},
		methods: {
			cancelPWd() {
				this.$refs.uModal1.clearLoading();
			},
			confirmPwd() {
				this.showPwd = false;
			},
			checkUpdate() {
				var plam = uni.getSystemInfoSync().platform;
				//console.log(plam)
				//#ifndef H5
				if (plam == 'android') {
					console.log(this.version + '版本信息')
					var _version = (plus.runtime.version).split('.').join('');
					console.log(this.version + '版本对比' + _version)
					if (this.version != _version) {
						this.$request('Code/GetTheAppUpdateMsg').then(resMsg => {
							this.updateContent = resMsg;
							this.update = true;
						})
					} else
						this.$u.toast('已是最新版');

				}
				// #endif

				//#ifdef H5
				this.$u.toast('已是最新版');
				// #endif
			},
			confirmUpdate() {
				var plam = uni.getSystemInfoSync().platform;
				console.log(plam)
				//#ifndef H5
				if (plam == 'android') {
					this.$request('Code/GetTheAppUrl').then(
						resUrl => {
							console.log(resUrl)
							plus.runtime.openURL(resUrl);
							//this.url = res.data;
							console.log(resUrl + '版本地址')
						})
				}
				// #endif
			},
			confirm() {
				this.$globalState.S1600Info.Login = false;
				uni.reLaunch({
					url: "/pages/login/login?isNavgeto=true"
				});
			},
			cancel() {
				this.show = false;
			},
		}
	}
</script>

<style>
	.separate {
		margin-top: 100rpx;
		border-top: 1rpx solid #ececec;
	}
</style>